/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Admin_GenerateReportStore.java
 *
 * Created on Apr 7, 2011, 5:02:51 PM
 */
package admin_gui;

import admin.BusinessLogic.Validation;
import admin.Controller.StoreReportController;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

/**
 *
 * @author edaype
 */
public class Admin_GenerateReportStore extends javax.swing.JPanel implements Printable {

    /** Creates new form Admin_GenerateReportStore */
    private ArrayList<String> reporList;
    private StoreReportController storeReportController;
    private Vector<String> v_head;
    private boolean flag;
    private String sDate;
    private String eDate;
    private JPanel mainPanel;
    private String splitStartDate [];
    private String splitEndDate [];
    private Validation validation;
    public Admin_GenerateReportStore(ArrayList rlist,JPanel mainPanel) {
        validation = new Validation();
        flag = false;
        initComponents();
        this.reporList = rlist;
     //   this.mainPanel = mainPanel;
        storeReportController = new StoreReportController(mainPanel);
        v_head = new Vector();
        v_head.add("Store NAme");
        v_head.add("Orders");
        v_head.add("Sales");
        v_head.add("Profit");
        sDate = "";
        eDate = "";
    }

    public Admin_GenerateReportStore(ArrayList<String> reportList,
            JPanel mainPanel, String startDate, String endDate) {
        flag = false;
        initComponents();
        this.reporList = reportList;
   //     this.mainPanel = mainPanel;
        storeReportController = new StoreReportController(mainPanel);
        v_head = new Vector();
        v_head.add("Store NAme");
        v_head.add("Orders");
        v_head.add("Sales");
        v_head.add("Profit");
        splitStartDate = new String[3];
        splitEndDate = new String[3];
        splitStartDate = startDate.split("-");
        splitEndDate = startDate.split("-");
        FromMonthCombo.setSelectedItem(splitStartDate[1]);
        FromDayCombo.setSelectedItem(splitStartDate[2]);
        FromYearCombo.setSelectedItem(splitStartDate[0]);
        ToMonthCombo.setSelectedItem(splitEndDate[1]);
        ToDayCombo.setSelectedItem(splitEndDate[2]);
        ToYearCombo.setSelectedItem(splitEndDate[0]);
        sDate = "";
        eDate = "";
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        TitlePanel = new javax.swing.JPanel();
        TitleLabel = new javax.swing.JLabel();
        ChartButton = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        FromPanel = new javax.swing.JPanel();
        FromYearLabel = new javax.swing.JLabel();
        FromYearCombo = new javax.swing.JComboBox();
        FromDayCombo = new javax.swing.JComboBox();
        FromMonthLabel = new javax.swing.JLabel();
        FromDayLabel = new javax.swing.JLabel();
        FromLabel = new javax.swing.JLabel();
        FromMonthCombo = new javax.swing.JComboBox();
        ToPanel = new javax.swing.JPanel();
        TotYearLabel = new javax.swing.JLabel();
        ToYearCombo = new javax.swing.JComboBox();
        ToDayCombo = new javax.swing.JComboBox();
        ToMonthLabel = new javax.swing.JLabel();
        ToDayLabel = new javax.swing.JLabel();
        ToLabel = new javax.swing.JLabel();
        ToMonthCombo = new javax.swing.JComboBox();
        GoButton = new javax.swing.JButton();
        TotalPanel = new javax.swing.JPanel();
        ItemLabel = new javax.swing.JLabel();
        TotalLabel = new javax.swing.JLabel();
        SalesLabel = new javax.swing.JLabel();
        ItemsOut = new javax.swing.JLabel();
        SalesOut = new javax.swing.JLabel();
        ProfitOut = new javax.swing.JLabel();
        ProfitLabel = new javax.swing.JLabel();
        ResultPane = new javax.swing.JScrollPane();
        ResultTable = new javax.swing.JTable();
        jButton2 = new javax.swing.JButton();

        setBackground(new java.awt.Color(255, 255, 255));

        TitlePanel.setBackground(new java.awt.Color(255, 255, 255));

        TitleLabel.setFont(new java.awt.Font("Copperplate Gothic Bold", 2, 30));
        TitleLabel.setText("Sales Report (Store)");

        ChartButton.setFont(new java.awt.Font("Tahoma", 0, 18));
        ChartButton.setText("Profit Chart");
        ChartButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ChartButtonActionPerformed(evt);
            }
        });

        jButton1.setFont(new java.awt.Font("Tahoma", 0, 18));
        jButton1.setText("Sales Chart");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton3.setFont(new java.awt.Font("Tahoma", 0, 18));
        jButton3.setText("Print");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout TitlePanelLayout = new javax.swing.GroupLayout(TitlePanel);
        TitlePanel.setLayout(TitlePanelLayout);
        TitlePanelLayout.setHorizontalGroup(
            TitlePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(TitlePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(TitleLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 361, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(ChartButton, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton3)
                .addContainerGap())
        );
        TitlePanelLayout.setVerticalGroup(
            TitlePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, TitlePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(TitlePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 51, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, TitlePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(TitleLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE)
                        .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE)
                        .addComponent(ChartButton, javax.swing.GroupLayout.DEFAULT_SIZE, 50, Short.MAX_VALUE)))
                .addContainerGap())
        );

        FromPanel.setBackground(new java.awt.Color(255, 255, 255));

        FromYearLabel.setFont(new java.awt.Font("Tahoma", 0, 18));
        FromYearLabel.setText("Year");

        FromYearCombo.setFont(new java.awt.Font("Tahoma", 0, 18));
        FromYearCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2009", "2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020" }));

        FromDayCombo.setFont(new java.awt.Font("Tahoma", 0, 18));
        FromDayCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));

        FromMonthLabel.setFont(new java.awt.Font("Tahoma", 0, 18));
        FromMonthLabel.setText("Month");

        FromDayLabel.setFont(new java.awt.Font("Tahoma", 0, 18));
        FromDayLabel.setText("Day");

        FromLabel.setFont(new java.awt.Font("Tahoma", 0, 24));
        FromLabel.setText("From");

        FromMonthCombo.setFont(new java.awt.Font("Tahoma", 0, 18));
        FromMonthCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" }));

        javax.swing.GroupLayout FromPanelLayout = new javax.swing.GroupLayout(FromPanel);
        FromPanel.setLayout(FromPanelLayout);
        FromPanelLayout.setHorizontalGroup(
            FromPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, FromPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(FromLabel)
                .addGap(27, 27, 27)
                .addGroup(FromPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(FromPanelLayout.createSequentialGroup()
                        .addComponent(FromMonthCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(FromDayCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(FromYearCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, FromPanelLayout.createSequentialGroup()
                        .addComponent(FromMonthLabel)
                        .addGap(67, 67, 67)
                        .addComponent(FromDayLabel)
                        .addGap(71, 71, 71)
                        .addComponent(FromYearLabel)
                        .addGap(35, 35, 35)))
                .addGap(64, 64, 64))
        );
        FromPanelLayout.setVerticalGroup(
            FromPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(FromPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(FromPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(FromYearLabel)
                    .addComponent(FromDayLabel)
                    .addComponent(FromMonthLabel))
                .addGap(4, 4, 4)
                .addGroup(FromPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(FromMonthCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(FromDayCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(FromYearCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(FromLabel))
                .addContainerGap())
        );

        ToPanel.setBackground(new java.awt.Color(255, 255, 255));

        TotYearLabel.setFont(new java.awt.Font("Tahoma", 0, 18));
        TotYearLabel.setText("Year");

        ToYearCombo.setFont(new java.awt.Font("Tahoma", 0, 18));
        ToYearCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2009", "2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020" }));

        ToDayCombo.setFont(new java.awt.Font("Tahoma", 0, 18));
        ToDayCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));

        ToMonthLabel.setFont(new java.awt.Font("Tahoma", 0, 18));
        ToMonthLabel.setText("Month");

        ToDayLabel.setFont(new java.awt.Font("Tahoma", 0, 18));
        ToDayLabel.setText("Day");

        ToLabel.setFont(new java.awt.Font("Tahoma", 0, 24));
        ToLabel.setText("To");

        ToMonthCombo.setFont(new java.awt.Font("Tahoma", 0, 18));
        ToMonthCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" }));

        javax.swing.GroupLayout ToPanelLayout = new javax.swing.GroupLayout(ToPanel);
        ToPanel.setLayout(ToPanelLayout);
        ToPanelLayout.setHorizontalGroup(
            ToPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ToPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(ToLabel)
                .addGap(26, 26, 26)
                .addGroup(ToPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(ToPanelLayout.createSequentialGroup()
                        .addComponent(ToMonthCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ToDayCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ToYearCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ToPanelLayout.createSequentialGroup()
                        .addComponent(ToMonthLabel)
                        .addGap(67, 67, 67)
                        .addComponent(ToDayLabel)
                        .addGap(71, 71, 71)
                        .addComponent(TotYearLabel)
                        .addGap(35, 35, 35)))
                .addGap(63, 63, 63))
        );
        ToPanelLayout.setVerticalGroup(
            ToPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ToPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(ToPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TotYearLabel)
                    .addComponent(ToDayLabel)
                    .addComponent(ToMonthLabel))
                .addGap(4, 4, 4)
                .addGroup(ToPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ToMonthCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ToDayCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ToYearCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ToLabel))
                .addContainerGap())
        );

        GoButton.setFont(new java.awt.Font("Tahoma", 0, 24));
        GoButton.setText("Go");
        GoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                GoButtonActionPerformed(evt);
            }
        });

        TotalPanel.setBackground(new java.awt.Color(255, 255, 255));

        ItemLabel.setFont(new java.awt.Font("Tahoma", 0, 14));
        ItemLabel.setText("Orders:");

        TotalLabel.setFont(new java.awt.Font("Tahoma", 0, 18));
        TotalLabel.setText("Total -->");

        SalesLabel.setFont(new java.awt.Font("Tahoma", 0, 14));
        SalesLabel.setText("Sales:$");

        ItemsOut.setFont(new java.awt.Font("Tahoma", 0, 14));
        ItemsOut.setText("0");

        SalesOut.setFont(new java.awt.Font("Tahoma", 0, 14));
        SalesOut.setText("0.00");

        ProfitOut.setFont(new java.awt.Font("Tahoma", 0, 14));
        ProfitOut.setText("0.00");

        ProfitLabel.setFont(new java.awt.Font("Tahoma", 0, 14));
        ProfitLabel.setText("Profit: $");

        javax.swing.GroupLayout TotalPanelLayout = new javax.swing.GroupLayout(TotalPanel);
        TotalPanel.setLayout(TotalPanelLayout);
        TotalPanelLayout.setHorizontalGroup(
            TotalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(TotalPanelLayout.createSequentialGroup()
                .addGap(42, 42, 42)
                .addComponent(TotalLabel)
                .addGap(53, 53, 53)
                .addComponent(ItemLabel)
                .addGap(18, 18, 18)
                .addComponent(ItemsOut)
                .addGap(34, 34, 34)
                .addComponent(SalesLabel)
                .addGap(18, 18, 18)
                .addComponent(SalesOut)
                .addGap(47, 47, 47)
                .addComponent(ProfitLabel)
                .addGap(18, 18, 18)
                .addComponent(ProfitOut)
                .addContainerGap(273, Short.MAX_VALUE))
        );
        TotalPanelLayout.setVerticalGroup(
            TotalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, TotalPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(TotalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ProfitLabel)
                    .addComponent(ProfitOut)
                    .addComponent(TotalLabel)
                    .addComponent(ItemLabel)
                    .addComponent(ItemsOut)
                    .addComponent(SalesLabel)
                    .addComponent(SalesOut)))
        );

        ResultTable.setFont(new java.awt.Font("Tahoma", 0, 14));
        ResultTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Store Name", "Orders", "Sales", "Profit"
            }
        ));
        ResultPane.setViewportView(ResultTable);

        jButton2.setFont(new java.awt.Font("Tahoma", 0, 18));
        jButton2.setText("<Back");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(TotalPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(FromPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 413, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(28, 28, 28)
                                .addComponent(ToPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 377, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(51, 51, 51)
                        .addComponent(GoButton, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(31, 31, 31)
                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(ResultPane, javax.swing.GroupLayout.DEFAULT_SIZE, 768, Short.MAX_VALUE)
                            .addComponent(TitlePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(FromPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ToPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(60, 60, 60)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jButton2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(GoButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(ResultPane, javax.swing.GroupLayout.DEFAULT_SIZE, 368, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(TotalPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(TitlePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void GoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_GoButtonActionPerformed
        String startDate = FromDayCombo.getSelectedItem().toString();
        String startMonth = FromMonthCombo.getSelectedItem().toString();
        String startYear = FromYearCombo.getSelectedItem().toString();
        String endDate = ToDayCombo.getSelectedItem().toString();
        String endMonth = ToMonthCombo.getSelectedItem().toString();
        String endYear = ToYearCombo.getSelectedItem().toString();
        if (validation.validateReportDate(Integer.parseInt(startDate), Integer.parseInt(startMonth), Integer.parseInt(startYear),
                Integer.parseInt(endDate), Integer.parseInt(endMonth), Integer.parseInt(endYear))) {
        sDate = startYear + "-" +startMonth + "-" + startDate;
        eDate = endYear + "-" + endMonth + "-" + endDate;
  //      System.out.println("start date: " + sDate);
        storeReportController.showStoreReportTable(ResultTable, reporList, sDate,
                eDate, v_head);
        ArrayList<Double> temp = new ArrayList<Double>();
        temp = storeReportController.getTotalInfo();
        ItemsOut.setText("" + (int) (Math.round(temp.get(0) * 100.0) / 100.0));
        String amount =
                (new BigDecimal(Math.round(temp.get(1) * 100.0) / 100.0)).toString();
        SalesOut.setText(amount.substring(0, amount.indexOf(".") + 3));
        amount =
                (new BigDecimal(Math.round(temp.get(2) * 100.0) / 100.0)).toString();
        ProfitOut.setText(amount.substring(0, amount.indexOf(".") + 3));
        flag = true;
        } else {
            JOptionPane.showMessageDialog(null, "Invalid Date!",
                    "Error", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_GoButtonActionPerformed

    private void ChartButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ChartButtonActionPerformed
        if (!flag) {
            JOptionPane.showMessageDialog(null, "Please generate report first!",
                    "Error", JOptionPane.ERROR_MESSAGE);
        } else {
            storeReportController.generateReportChart(reporList, sDate, eDate,
                    false);
            flag = false;
        }
    }//GEN-LAST:event_ChartButtonActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        if (!flag) {
            JOptionPane.showMessageDialog(null, "Please generate report first!",
                    "Error", JOptionPane.ERROR_MESSAGE);
        } else {
            storeReportController.generateReportChart(reporList, sDate, eDate,
                    true);
            flag = false;
        }
    }//GEN-LAST:event_jButton1ActionPerformed
    public int print(Graphics g, PageFormat pageFormat,
            int pageIndex) throws PrinterException {
        Graphics2D g2 = (Graphics2D) g;
        g2.setColor(Color.black);
        int fontHeight = g2.getFontMetrics().getHeight();
        int fontDesent = g2.getFontMetrics().getDescent();

        //leave room for page number
        double pageHeight =
                pageFormat.getImageableHeight() - fontHeight;
        double pageWidth =
                pageFormat.getImageableWidth();
        double tableWidth = (double) ResultTable.getColumnModel().
                getTotalColumnWidth();
        double scale = 1;
        if (tableWidth >= pageWidth) {
            scale = pageWidth / tableWidth;
        }

        double headerHeightOnPage =
                ResultTable.getTableHeader().getHeight() * scale;
        double tableWidthOnPage = tableWidth * scale;

        double oneRowHeight = (ResultTable.getRowHeight() +
                ResultTable.getRowMargin()) * scale;
        int numRowsOnAPage =
                (int) ((pageHeight - headerHeightOnPage) /
                oneRowHeight);
        double pageHeightForTable = oneRowHeight *
                numRowsOnAPage;
        int totalNumPages =
                (int) Math.ceil(((double) ResultTable.getRowCount()) /
                numRowsOnAPage);
        if (pageIndex >= totalNumPages) {
            return NO_SUCH_PAGE;
        }

        g2.translate(pageFormat.getImageableX(),
                pageFormat.getImageableY());
//bottom center
        g2.drawString("Page: " + (pageIndex + 1),
                (int) pageWidth / 2-35, (int) (pageHeight + fontHeight -
                fontDesent));

        g2.translate(0f, headerHeightOnPage);
        g2.translate(0f, -pageIndex * pageHeightForTable);

        //If this piece of the table is smaller
        //than the size available,
        //clip to the appropriate bounds.
        if (pageIndex + 1 == totalNumPages) {
            int lastRowPrinted =
                    numRowsOnAPage * pageIndex;
            int numRowsLeft =
                    ResultTable.getRowCount() - lastRowPrinted;
            g2.setClip(0,
                    (int) (pageHeightForTable * pageIndex),
                    (int) Math.ceil(tableWidthOnPage),
                    (int) Math.ceil(oneRowHeight *
                    numRowsLeft));
        } //else clip to the entire area available.
        else {
            g2.setClip(0,
                    (int) (pageHeightForTable * pageIndex),
                    (int) Math.ceil(tableWidthOnPage),
                    (int) Math.ceil(pageHeightForTable));
        }

        g2.scale(scale, scale);
        ResultTable.paint(g2);
        g2.scale(1 / scale, 1 / scale);
        g2.translate(0f, pageIndex * pageHeightForTable);
        g2.translate(0f, -headerHeightOnPage);
        g2.setClip(0, 0,
                (int) Math.ceil(tableWidthOnPage),
                (int) Math.ceil(headerHeightOnPage));
        g2.scale(scale, scale);
        ResultTable.getTableHeader().paint(g2);
        //paint header at top

        return Printable.PAGE_EXISTS;
    }
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        storeReportController.goBackSelectReport();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        PrinterJob pj = PrinterJob.getPrinterJob();
                pj.setPrintable(Admin_GenerateReportStore.this);
                pj.printDialog();
                try {
                    pj.print();
                } catch (Exception PrintException) {
                }
    }//GEN-LAST:event_jButton3ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton ChartButton;
    private javax.swing.JComboBox FromDayCombo;
    private javax.swing.JLabel FromDayLabel;
    private javax.swing.JLabel FromLabel;
    private javax.swing.JComboBox FromMonthCombo;
    private javax.swing.JLabel FromMonthLabel;
    private javax.swing.JPanel FromPanel;
    private javax.swing.JComboBox FromYearCombo;
    private javax.swing.JLabel FromYearLabel;
    private javax.swing.JButton GoButton;
    private javax.swing.JLabel ItemLabel;
    private javax.swing.JLabel ItemsOut;
    private javax.swing.JLabel ProfitLabel;
    private javax.swing.JLabel ProfitOut;
    private javax.swing.JScrollPane ResultPane;
    private javax.swing.JTable ResultTable;
    private javax.swing.JLabel SalesLabel;
    private javax.swing.JLabel SalesOut;
    private javax.swing.JLabel TitleLabel;
    private javax.swing.JPanel TitlePanel;
    private javax.swing.JComboBox ToDayCombo;
    private javax.swing.JLabel ToDayLabel;
    private javax.swing.JLabel ToLabel;
    private javax.swing.JComboBox ToMonthCombo;
    private javax.swing.JLabel ToMonthLabel;
    private javax.swing.JPanel ToPanel;
    private javax.swing.JComboBox ToYearCombo;
    private javax.swing.JLabel TotYearLabel;
    private javax.swing.JLabel TotalLabel;
    private javax.swing.JPanel TotalPanel;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    // End of variables declaration//GEN-END:variables
}
